
/*/////////////////////////////////////////////////////////////////////////////
File Name : Serial_Flash.c
Control Function : SIO7 of R5F3640MDFB
EEPROM Size : 2MBit
EEPROM Bander : Winbond
EEPROM Communication Mode : SPI
EEPROM Clock Freq = 33MHz ( Clock High, Low Time 6nsec)
/////////////////////////////////////////////////////////////////////////////*/

#include	"SysConfig.h"
#include	"Define.h"
#include	"Port.h"
#include	"Serial_Flash.h"
#ifdef  BLUETOOTH
#include	"Bluetooth.h"
#endif
#ifdef  PHONE_BOOK
#include	"PhoneBook.h"
#endif
#include	"Model_Option.h"

#ifdef  SERIAL_FLASH

#ifdef  PHONE_BOOK

extern unsigned short usPBAP_ListCnt;
extern PBAP_LIST	sPBAP_List;

#endif

#ifdef  BLUETOOTH
extern BT_DEVICE	sBT_ConnectedDevice;
#endif
unsigned char ucSF_TX_DataBuf[SF_TX_DATA_SIZE];
unsigned short usSF_TX_wPtr;
unsigned short usSF_TX_sPtr;
unsigned char ucSF_RX_DataBuf[SF_RX_DATA_SIZE];
unsigned char ucSF_RX_wPtr;
unsigned char ucSF_RX_rPtr;
unsigned char ucSF_RX_Cnt;
unsigned char ucSF_RX_Data;
unsigned long int  uiSF_TotalSize;
unsigned char ucSF_Sequence;
unsigned char ucSF_ReadStatus;
unsigned char ucSF_WriteStatus;
unsigned long int uiSF_EraseAddress;
unsigned char ucSF_EraseSectorNumber;		// 64 sector
/*//////////////////////////////////////////////////////
Block0 : 0 ~ 15 Sector
Block1 : 16 ~ 31 Sector
Block2 : 32 ~ 47 Sector
Block3 : 48 ~ 63 Sector
Sector is 4KB ( 4096 Byte )
//////////////////////////////////////////////////////*/
unsigned char ucSF_DeviceID;
unsigned char ucSF_ManufacurID;
unsigned char ucSF_CommunicationSequence;
unsigned char ucSF_RequestWriteClose;
unsigned long int uiSF_WriteAddress;
unsigned char ucSF_ColdStart;
unsigned char ucSF_WriteEndRequest;

unsigned char SF_SetInstruction(unsigned char ucIns);

void SF_Delay(unsigned char ucCnt)
{
	unsigned char i;

	for(i = 0; i < ucCnt; ++i)
	{
		asm("nop");
	}
}

void SF_ErasePhoneData_Request(void)
{
	ucSF_EraseSectorNumber = SF_PHONEBOOK_ADDR / SF_SECTOR_SIZE;
	ucSF_CommunicationSequence = SF_SEQ_ERASE_PHONE_DATA;
	
	SF_SetInstruction(SF_INS_WRITE_ENABLE);
}

unsigned char SF_CommunicationActived(void)
{	
	if  (ucSF_CommunicationSequence == SF_SEQ_IDLE)
	{
		return(0);
	}
	return(1);
}

unsigned char SF_CommunicationHold(void)
{	
	if  (ucSF_CommunicationSequence == SF_SEQ_WRITE_HOLD)
	{
		return(1);
	}
	return(0);
}

unsigned char SF_CommunicationWriteEnd(void)
{
	if  (ucSF_CommunicationSequence == SF_SEQ_WRITE_END)
	{
		return(1);
	}
	return(0);
}

unsigned short SF_PhoneDataReady(void)
{
	if  (ucSF_CommunicationSequence == SF_SEQ_PHONE_DATA_READ_COMPLETE)
	{
		ucSF_CommunicationSequence = SF_SEQ_PHONE_DATA_READ_NEXT;
		return(1);
	}
	return(0);
}

unsigned char SF_TX_SetData(unsigned char ucData)
{
	ucSF_TX_DataBuf[usSF_TX_wPtr] = ucData;
	++usSF_TX_wPtr;
	usSF_TX_wPtr = usSF_TX_wPtr % SF_TX_DATA_SIZE;
}

unsigned char SF_TX_GetData(void)
{
	unsigned char ucData;

	ucData = ucSF_TX_DataBuf[usSF_TX_sPtr];
	++usSF_TX_sPtr;
	usSF_TX_sPtr = usSF_TX_sPtr % SF_TX_DATA_SIZE;
	
	return(ucData);
}

unsigned char SF_RX_GetData(void)
{
	unsigned char ucData;
	
	ucData = ucSF_RX_DataBuf[ucSF_RX_rPtr];
	++ucSF_RX_rPtr;
	ucSF_RX_rPtr = ucSF_RX_rPtr % SF_RX_DATA_SIZE;

	return(ucData);
}

unsigned char SF_RX_SetData(unsigned char ucData)
{	
	ucSF_RX_DataBuf[ucSF_RX_wPtr] = ucData;
	++ucSF_RX_wPtr;
	ucSF_RX_wPtr = ucSF_RX_wPtr % SF_RX_DATA_SIZE;
}

unsigned short SF_RX_GetSize(void)
{
	if  (ucSF_RX_wPtr < ucSF_RX_rPtr)
	{
		return((ucSF_RX_wPtr + SF_RX_DATA_SIZE) - ucSF_RX_rPtr);
	}
	
	return(ucSF_RX_wPtr - ucSF_RX_rPtr);
}

unsigned short SF_TX_GetDataCnt(void)
{
	if  (usSF_TX_wPtr == usSF_TX_sPtr)
	{
		return(0);
	}
	if  (usSF_TX_wPtr < usSF_TX_sPtr)
	{
		return((usSF_TX_wPtr + SF_TX_DATA_SIZE) - usSF_TX_sPtr);
	}
	
	return(usSF_TX_wPtr - usSF_TX_sPtr);
}

void SF_Receive_Int(void)
{
	ucSF_RX_Data = u7rb;
	SF_RX_SetData(ucSF_RX_Data);
	--ucSF_RX_Cnt;
	if  (ucSF_RX_Cnt == 0)
	{
		re_u7c1 = 0;
		te_u7c1 = 0;
		s7ric = 0x00;
		s7tic = 0x00;

		ucSF_CommunicationSequence = SF_SEQ_IDLE;
	}
	else
	{
		u7tb = 0x00;	// Send trash Data for genrator
	}
}

unsigned char SF_GetReceiveDataNumber(void)
{
	return(ucSF_RX_Cnt);
}

void SF_Send_Int(void)
{
	++uiSF_WriteAddress;
	if  ((uiSF_WriteAddress % SF_PAGE_SIZE) == 0)
	{
		te_u7c1 = 0;// Hold....
		if  (ucSF_WriteEndRequest == 1)
		{
			ucSF_CommunicationSequence = SF_SEQ_WRITE_END;
		}
		else
		{
			ucSF_CommunicationSequence = SF_SEQ_WRITE_HOLD;
		}
	}
	else if  (usSF_TX_wPtr == usSF_TX_sPtr)
	{
		te_u7c1 = 0;
		if  (ucSF_WriteEndRequest == 1)
		{
			ucSF_CommunicationSequence = SF_SEQ_WRITE_END;
		}
		else
		{
			ucSF_CommunicationSequence = SF_SEQ_WRITE_WAIT;
		}
	}
	else
	{
		u7tb = SF_TX_GetData();
	}
}

void SF_TX_Data(unsigned char ucData)
{
	unsigned short i;

	te_u7c1 = 1;
	s7tic = 0x00;
	s7ric = 0x00;
	u7tb = ucData;

	for(i = 0; i < 3000; ++i)
	{
		if  (ir_s7tic == 1)
		{
			break;
		}
	}
	
	te_u7c1 = 0;
	SF_Delay(20);
}

unsigned char SF_RX_Data(void)
{
	unsigned short i;

	re_u7c1 = 1;
	te_u7c1 = 1;
	s7tic = 0x00;
	s7ric = 0x00;
	u7tb = 0x00;	// Send trash Data for genrator
	
	for(i = 0; i < 3000; ++i)
	{
		if  (ir_s7tic == 1)
		{
			break;
		}
	}

	re_u7c1 = 0;
	te_u7c1 = 0;

	ucSF_RX_Data = u7rb;

	SF_Delay(20);

	return(ucSF_RX_Data);
}

unsigned char SF_WriteData_ReStart(void)
{
	unsigned int uiAddr;

	ucSF_CommunicationSequence = SF_SEQ_WRITE;
	u7tb = SF_TX_GetData();
	te_u7c1 = 1;
}

unsigned char SF_RequestWriteClose(void)
{
	if	(ucSF_CommunicationSequence == SF_SEQ_WRITE)
	{
		ucSF_RequestWriteClose = 1;
	}
}

unsigned char SF_WriteData_Start(unsigned long int uiAddrs)
{
	unsigned short i;

	SF_SetInstruction(SF_INS_WRITE_ENABLE);
	for(i = 0; i < 2000; ++i)
	{
		SF_Delay(10);
		SF_SetInstruction(SF_INS_READ_STATUS);
		if  ((ucSF_ReadStatus & 0x01) == 0)
		{
			break;
		}
	}
	SF_Delay(10);
	
	ucSF_CommunicationSequence = SF_SEQ_WRITE;

	PO_SF_WP = 1;
	PO_SF_CS = 0;
	SF_Delay(5);		// 5nsec
	
	SF_TX_Data(SF_INS_PAGE_PROGRAM);
	SF_TX_Data((unsigned char)(uiAddrs >> 16));
	SF_TX_Data((unsigned char)(uiAddrs >> 8));
	SF_TX_Data((unsigned char)uiAddrs);

	SF_Delay(20);		// 5nsec

	u7tb = SF_TX_GetData();
	s7tic = 0x05;	// Interrupt enable & Level Set 5
	te_u7c1 = 1;
}

unsigned char SF_WriteData_End(void)
{
	ucSF_CommunicationSequence = SF_SEQ_IDLE;

	PO_SF_WP = 0;
	PO_SF_CS = 1;
	SF_Delay(0);		// 5nsec
	
	s7tic = 0x00;	// Interrupt enable & Level Set 5
	te_u7c1 = 0;

	SF_Delay(20);	
	SF_SetInstruction(SF_INS_WRITE_DISABLE);
}

unsigned char SF_Read_Start(unsigned long int uiAddr, unsigned char ucCnt)
{
	LOG_SF("SF_Read_Start");
	LOG_SF("ADDR:%d",uiAddr);
	LOG_SF("CNT:%d",ucCnt);
	ucSF_RX_Cnt = ucCnt;
	ucSF_CommunicationSequence = SF_SEQ_READ;

	PO_SF_WP = 0;
	PO_SF_CS = 0;
	SF_Delay(5);		// 5nsec
	
	SF_TX_Data(SF_INS_READ_DATA);
	SF_TX_Data((unsigned char)(uiAddr >> 16));
	SF_TX_Data((unsigned char)(uiAddr >> 8));
	SF_TX_Data((unsigned char)(uiAddr));
	
	SF_Delay(30);		// 5nsec
	re_u7c1 = 1;
	te_u7c1 = 1;
//	u7rrm = 1;
	s7ric = 0x05;	// Interrupt enable & Level Set 5
	s7tic = 0;
	u7tb = 0x00;	// Send trash Data for genrator
}

unsigned char SF_Read_End(void)
{
	ucSF_CommunicationSequence = SF_SEQ_IDLE;

	SF_Delay(20);
	PO_SF_WP = 0;
	PO_SF_CS = 1;
	
	s7ric = 0x00;	// Interrupt enable & Level Set 5
	re_u7c1 = 0;
	te_u7c1 = 0;

	SF_Delay(20);
}


unsigned long ulSF_UniqueID;
unsigned char SF_SetInstruction(unsigned char ucIns)
{
	PO_SF_CS = 0;
	SF_Delay(5);		// 5nsec
	SF_TX_Data(ucIns);
	switch  (ucIns)
	{
		case SF_INS_WRITE_ENABLE:
		case SF_INS_WRITE_ENABLE_VOLATILE:
		case SF_INS_WRITE_DISABLE:
			break;
		case SF_INS_READ_STATUS:
			SF_Delay(50);
			ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
	//		ucSF_ReadStatus = SF_RX_Data();
			break;
		case SF_INS_WRITE_STATUS:
			SF_TX_Data(ucSF_WriteStatus);
			break;
		case SF_INS_READ_DATA:
		case SF_INS_FAST_READ:
		case SF_INS_FAST_READ_DUAL_OUPUT:
		case SF_INS_FAST_READ_DUAL_IO:
		case SF_INS_PAGE_PROGRAM:
			break;
		case SF_INS_SECTOR_ERASE_4K:
		case SF_INS_BLOCK_ERASE_32K:
		case SF_INS_BLOCK_ERASE_64K:
			SF_TX_Data((unsigned char)(uiSF_EraseAddress >> 16));
			SF_TX_Data((unsigned char)(uiSF_EraseAddress >> 8));
			SF_TX_Data((unsigned char)(uiSF_EraseAddress));
			break;
		case SF_INS_CHIP_ERASE:
		case SF_INS_POWER_DOWN:
			break;
		case SF_INS_RELEASE_POWER_DOWN:
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_Delay(50);
			ucSF_DeviceID = SF_RX_Data();
			break;
		case SF_INS_DEVICE_ID:
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
	//		SF_Delay(200);
	//		SF_Delay(200);
	//		SF_Delay(200);
	//		SF_Delay(200);
	//		SF_Delay(200);
			ucSF_ManufacurID = SF_RX_Data();
			ucSF_DeviceID = SF_RX_Data();
			break;
		case SF_INS_DEVICE_ID_DUAL:
		case SF_INS_JEDEC_ID:
			break;
		case SF_INS_READ_UNIQUE_ID:
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_TX_Data(0x00);	// Dummy
			SF_Delay(50);
			ulSF_UniqueID = 0;
			ulSF_UniqueID = SF_RX_Data();
			ulSF_UniqueID = ((ulSF_UniqueID << 8) & 0xFFFFFF00) | SF_RX_Data();
			ulSF_UniqueID = ((ulSF_UniqueID << 8) & 0xFFFFFF00) | SF_RX_Data();
			ulSF_UniqueID = ((ulSF_UniqueID << 8) & 0xFFFFFF00) | SF_RX_Data();
			ulSF_UniqueID = ((ulSF_UniqueID << 8) & 0xFFFFFF00) | SF_RX_Data();
			break;
	}
	
	SF_Delay(20);		// 5nsec
	PO_SF_CS = 1;
}

void SF_WriteCloseRequest(void)
{
	ucSF_WriteEndRequest = 1;
}

unsigned char ucSF_Test_enable;
unsigned char ucSF_Test_Data;

void SF_Test(void)
{
	unsigned char *ucData;
	unsigned char i;
	
	if  (ucSF_Test_enable == 1)
	{
		if  (SF_TX_GetDataCnt() != 0)
		{
			return;
		}
		if  (usPBAP_ListCnt < 5)
		{
			sPBAP_List.usNumber = usPBAP_ListCnt;
			ucData = &sPBAP_List.ucName[0];
			for(i = 0; i < sizeof(PBAP_LIST); ++i)
			{
		#ifdef  SERIAL_FLASH
				SF_TX_SetData(*ucData);
		#endif
				++ucData;
			}
			++usPBAP_ListCnt;
		}
		else
		{
			ucSF_Test_enable = 0;
			ucSF_WriteEndRequest = 1;
		}
	}
	else
	{
		uiSF_WriteAddress = SF_PHONEBOOK_ADDR;
		usPBAP_ListCnt = 0;
	}
}

void SF_WriteBluetoothDeviceAddress(void)
{
	uiSF_WriteAddress = SF_BT_DEVICE_ADDR;
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[0]);
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[1]);
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[2]);
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[3]);
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[4]);
	SF_TX_SetData(sBT_ConnectedDevice.ucDeviceAdr[5]);
	SF_WriteData_Start(uiSF_WriteAddress);
}

void SF_ReadWriteMain(void)
{	
	switch  (ucSF_CommunicationSequence)
	{
		case SF_SEQ_IDLE:
			if  (SF_TX_GetDataCnt() != 0)
			{
				LOG_SF("SF_SEQ_IDLE");
				SF_WriteData_Start(uiSF_WriteAddress);
				LOG_SF("%d",uiSF_WriteAddress);
			}
			break;
		case SF_SEQ_WRITE:
			break;
		case SF_SEQ_WRITE_WAIT:
			if  (SF_TX_GetDataCnt() != 0)
			{
				LOG_SF("SF_SEQ_WRITE_WAIT:ReStart");
				LOG_SF("%d",uiSF_WriteAddress);
				SF_WriteData_ReStart();
			}
			else
			{
				if  (ucSF_WriteEndRequest == 1)
				{
					ucSF_CommunicationSequence = SF_SEQ_WRITE_END;
				}
			}
			break;
		case SF_SEQ_WRITE_HOLD:
			if  (SF_TX_GetDataCnt() != 0)
			{
				LOG_SF("SF_SEQ_WRITE_HOLD");
				LOG_SF("%d",uiSF_WriteAddress);
				SF_WriteData_End();
				ucSF_CommunicationSequence = SF_SEQ_WRITE_START;
			}  else  {
				if  (ucSF_WriteEndRequest == 1)
				{
					ucSF_CommunicationSequence = SF_SEQ_WRITE_END;
				}
			}
			break;
		case SF_SEQ_WRITE_START:
			if  (SF_TX_GetDataCnt() != 0)
			{
				LOG_SF("SF_SEQ_WRITE_START");
				LOG_SF("%d",uiSF_WriteAddress);
				SF_WriteData_Start(uiSF_WriteAddress);
			}
			break;
		case SF_SEQ_WRITE_END:
			LOG_SF("SF_SEQ_WRITE_END");
			LOG_SF("%d",uiSF_WriteAddress);
			SF_WriteData_End();
			ucSF_WriteEndRequest = 0;
			break;
		case SF_SEQ_ERASE_BLOCK:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  ((ucSF_ReadStatus & 0x02) == 0x00)
			{
				SF_SetInstruction(SF_INS_WRITE_ENABLE);
				return;
			}
			uiSF_EraseAddress = ucSF_EraseSectorNumber * SF_SECTOR_SIZE;
			SF_SetInstruction(SF_INS_SECTOR_ERASE_4K);
			ucSF_CommunicationSequence = SF_SEQ_ERASE_BLOCK_WAIT;
			break;
		case SF_SEQ_ERASE_BLOCK_WAIT:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  ((ucSF_ReadStatus & 0x01) == 0x01)
			{
				return;
			}
			ucSF_CommunicationSequence = SF_SEQ_IDLE;
			SF_SetInstruction(SF_INS_WRITE_DISABLE);
			break;
		case SF_SEQ_ERASE_PHONE_DATA:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  ((ucSF_ReadStatus & 0x02) == 0x00)
			{
				SF_SetInstruction(SF_INS_WRITE_ENABLE);
				return;
			}
			SF_SetInstruction(SF_INS_CHIP_ERASE);
			ucSF_CommunicationSequence = SF_SEQ_ERASE_PHONE_DATA_WAIT;
			break;
		case SF_SEQ_ERASE_PHONE_DATA_WAIT:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  ((ucSF_ReadStatus & 0x01) == 0x01)
			{
				return;
			}
			SF_SetInstruction(SF_INS_WRITE_DISABLE);
			ucSF_CommunicationSequence = SF_SEQ_IDLE;
			break;
	}
}

void SF_Main(void)
{
	if  (OPT_GetOption(OPT_MASK_BT) == 0)
	{
		return;
	}
	switch  (ucSF_Sequence)
	{
		case SF_SEQ_CHECK_ID:
			ucSF_ManufacurID = 0;
			ucSF_DeviceID = 0;
			SF_SetInstruction(SF_INS_DEVICE_ID);
			LOG_SF("ucSF_ManufacurID:%X",ucSF_ManufacurID);
			LOG_SF("ucSF_DeviceID:%X",ucSF_DeviceID);
			if  (ucSF_ManufacurID == SF_MANUF_ID_WINBOND)
			{
				switch  (ucSF_DeviceID)
				{
					case SF_DEVICE_ID_W25X20CL:
						uiSF_TotalSize = 262144;	// Byte
						break;
					case SF_DEVICE_ID_W25X10CL:
						uiSF_TotalSize = 131072;	// Byte
						break;
					case SF_DEVICE_ID_W25X05CL:
						uiSF_TotalSize = 65536;		// Byte
						break;
				}
				if  (ucSF_ColdStart == 1)
				{
					ucSF_Sequence = SF_SEQ_ERASE_ALL;
					ucSF_ColdStart = 0;
				}
				else
				{
					ucSF_Sequence = SF_SEQ_READY;
				}
//				ucSF_Sequence = SF_SEQ_READ_USERID;
			}
			else
			{
			}
			break;
		case SF_SEQ_READ_USERID:
			SF_Read_Start(0x000000, SF_USER_ID_SIZE);
			ucSF_Sequence = SF_SEQ_CHECK_USERID;
			break;
		case SF_SEQ_CHECK_USERID:
			if  (SF_RX_GetSize() > 3)
			{
				char cBuf[SF_USER_ID_SIZE];

				SF_Read_End();
				memset(&cBuf[0], 0x00, sizeof(cBuf));
				cBuf[0] = SF_RX_GetData();
				cBuf[1] = SF_RX_GetData();
				cBuf[2] = SF_RX_GetData();
				cBuf[3] = SF_RX_GetData();

				if  (memcmp(&cBuf[0], SF_USER_ID, SF_USER_ID_SIZE) == 0)
				{
					ucSF_Sequence = SF_SEQ_READY;
				}
				else
				{
					ucSF_Sequence = SF_SEQ_ERASE_ALL;
				}
			}
			break;
		case SF_SEQ_ERASE_ALL:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  ((ucSF_ReadStatus & 0x02) == 0x00)
			{
				SF_SetInstruction(SF_INS_WRITE_ENABLE);
				return;
			}
			SF_SetInstruction(SF_INS_CHIP_ERASE);
			ucSF_Sequence = SF_SEQ_ERASE_WAIT;
			break;
		case SF_SEQ_ERASE_WAIT:
			SF_SetInstruction(SF_INS_READ_STATUS);
			if  (ucSF_ReadStatus & 0x01)
			{
				return;
			}
			
			SF_SetInstruction(SF_INS_WRITE_DISABLE);
//			ucSF_Sequence = SF_SEQ_WRITE_USERID;
			ucSF_Sequence = SF_SEQ_READY;
			LOG_SF("SF ERASE OK");
			break;
		case SF_SEQ_WRITE_USERID:
			{
				unsigned char ucBuf[SF_USER_ID_SIZE];
				unsigned char i;

				memset(&ucBuf[0], 0x00, sizeof(ucBuf));
				memcpy(&ucBuf[0], SF_USER_ID, SF_USER_ID_SIZE);

				for(i = 0; i < SF_USER_ID_SIZE; ++i)
				{
					SF_TX_SetData(ucBuf[i]);
				}
			}
			SF_WriteData_Start(0x000000);
			while(1)
			{
				if  (ucSF_CommunicationSequence == SF_SEQ_WRITE_WAIT)
				{
					break;
				}
			}
			SF_WriteData_End();
			ucSF_Sequence = SF_SEQ_READ_USERID;
			break;
		case SF_SEQ_READY:
			SF_ReadWriteMain();
			break;
	}
}

#endif

